import React from "react";
import { useNavigate, useLocation } from "../react-router-dom";

function Login(){
  // const [ num, setNum ] = useState(1);
  const navigate = useNavigate();
  const location = useLocation();
  // 点击登录按钮的时候先设置 localStorage状态
  const login = () => {
    localStorage.setItem('login', 'true');
    let to="/";
    if(location.state){
      to = location.state.from || "/";
    }
    navigate(to);
  };

  return (
    <button onClick={login}>登录</button>
  )
};

export default Login;
